package org.example.blogger.service;

import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.example.blogger.mapper.BlogMapper;
import org.example.blogger.mapper.UserInfoMapper;
import org.example.blogger.model.BlogInfo;
import org.example.blogger.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class UserService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Autowired
    BlogMapper blogMapper;
    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //根据博客id,获取作者id
        //根据作者id,获取作者信息
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if (blogInfo == null && blogInfo.getUserId() <=0){
            log.error("博客不存在,或者作者信息不合法,blogId{}",blogId);
            return null;
        }
        return userInfoMapper.selectById(blogInfo.getUserId());
    }
}
